﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Carroit.Web.admin
{
    public partial class login : System.Web.UI.Page
    {
        public string VerifyStr = "<h3 class=\"form-title font-green\">管理员登录</h3>";
        public dynamic SiteConfig = new Evan.Model.DynamicModel();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SiteConfig = new Evan.DataBase.DbOperat("Versions").GetModel(1);
                SiteConfig.Set("WebPath", string.IsNullOrEmpty(SiteConfig.WebPath as string) ? "/" : SiteConfig.WebPath);
                SiteConfig.Set("WebAdminPath", SiteConfig.WebPath + SiteConfig.WebManagerPath + "/");

                string action = Evan.Common.CommFun.GetQueryString("action");
                if (!string.IsNullOrEmpty(action))
                {
                    if (action.ToUpper() == "loginout".ToUpper())
                    {
                        Evan.Member.Administrator.ClearAdminInfo();
                        Response.Redirect(SiteConfig.WebAdminPath + "login.aspx");
                    }
                }

                //检查是否登录状态中 
                if (Evan.Member.Administrator.IsAdminLogin())
                {
                    //如果在其它设备登录 , 此处的Cookie 登录依然管用 , 此做标记
                    Response.Redirect(SiteConfig.WebAdminPath + "index.aspx");
                }

                VerifySiteSiate();
                
            }
        }

        public void VerifySiteSiate()
        {
            Evan.Reg.VerifoNotice verifyRes = Evan.Reg.Security.CheckReg();
            if (verifyRes.Result)
            {
                VerifyStr = "<h3 class=\"form-title font-green\">管理员登录</h3>";
            }
            else
            {
                VerifyStr = "<h3 class=\"form-title font-red\">" + verifyRes.Reason + "</h3>";
                if (verifyRes.ExpiredDay == -1)
                {
                    VerifyStr += "<h4 class=\"font-red text-center\">您的后台已经暂停使用<br/>请立即联系您的客户经理</h4>";
                }
                else if (verifyRes.ExpiredDay <= 7)
                {
                    VerifyStr += "<h4 class=\"font-red text-center\">" + ((7 + 1) - verifyRes.ExpiredDay) + "天后后台将无法正常使用</h4>";
                }
                else
                {
                    VerifyStr += "<h4 class=\"font-red text-center\">您的后台已经暂停使用<br/>请立即联系您的客户经理</h4>";
                }
            }
        }

    }
}